<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath %>"><!-- 整个页面全部指定为这个地址 -->
    <meta charset="UTF-8">
    <title>衣物回收增加页面</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../res/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../res/layui/layui.js"></script>
    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async : false
        });
    </script>
    <style type="text/css">
        .layui-form-label {
            width: 70px;
        }

        .layui-input-block {
            width: 70%;
        }

        body {
            padding-top: 5px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" id="formDId">
    <div class="layui-form-item">
        <label class="layui-form-label">衣物名称</label>
        <div class="layui-input-block">
            <input type="text" name="coName" id="coName" required
                   lay-verify="required" placeholder="请输入衣物名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">请选择衣物类型</label>
        <div class="layui-input-block">
            <select id="clId" name="clId"  lay-filter="demo" lay-verify="required">
                <option value=""></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">衣物数量</label>
        <div class="layui-input-block">
            <input type="text" name="coNum" id="coNum" required
                   lay-verify="required|number" placeholder="请输入衣物数量" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    //全局同步
    $.ajaxSetup({
        async : false
    });



</script>
<script type="text/javascript">

    var form=null;
    layui.use('form', function(){

        form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            var formData = new FormData(document.getElementById("formDId"));;
            //var data={coName:$("#coName").val(),clId:$("#clId").val(),coNum:$("#coNum").val()};
            var url="../UserController/insertHuishou";
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            //parent.location.reload();
                        });


                    }else{
                        layer.msg(obj.msg);
                    }


                },
                error:function(e){
                    layer.msg("错误！！");
                }
            });
            return false;
        });
        athlete();
    });
    function athlete(){
        var urlFour="../UserController/selectType";
        var dataFour=null;
        $.post(urlFour,dataFour,function(obj){
            $.each(obj,function(index,item){
                $("#clId").append("<option value='"+item.clId+"'>"+item.clType+"</option>");
            });
            form.render('select');
        },"json");
    }
</script>
</body>
</html>